package com.crois.barrier.web.logo;

import com.alibaba.nacos.api.common.Constants;
import com.crois.barrier.common.utils.LogUtils;
import com.crois.barrier.common.utils.VersionUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.context.event.ApplicationEnvironmentPreparedEvent;
import org.springframework.boot.context.logging.LoggingApplicationListener;
import org.springframework.context.ApplicationListener;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;

/**
 * @author Hou Ze Yu
 * @description  DoorLogo
 * @date 2020/7/13
 */
@Component
@Order(LoggingApplicationListener.DEFAULT_ORDER + 1)
public class BarrierLogo implements ApplicationListener<ApplicationEnvironmentPreparedEvent> {

    private static final String BARRIER_LOGO =
            "    ___     ___     ___     ___     ___     ___     ___   \n" +
                    "  | _ )   /   \\   | _ \\   | _ \\   |_ _|   | __|   | _ \\  \n" +
                    "  | _ \\   | - |   |   /   |   /    | |    | _|    |   /  \n" +
                    "  |___/   |_|_|   |_|_\\   |_|_\\   |___|   |___|   |_|_\\  \n" +
                    "_|\"\"\"\"\"|_|\"\"\"\"\"|_|\"\"\"\"\"|_|\"\"\"\"\"|_|\"\"\"\"\"|_|\"\"\"\"\"|_|\"\"\"\"\"| \n" +
                    "\"`-0-0-'\"`-0-0-'\"`-0-0-'\"`-0-0-'\"`-0-0-'\"`-0-0-'\"`-0-0-' ";

    /**
     * logger.
     */
    private static final Logger LOGGER = LoggerFactory.getLogger(BarrierLogo.class);

    @Override
    public void onApplicationEvent(final ApplicationEnvironmentPreparedEvent event) {
        String bannerText = buildBannerText();
        LogUtils.info(LOGGER, () -> bannerText);
    }

    private String buildBannerText() {
        return Constants.LINE_SEPARATOR
                + Constants.LINE_SEPARATOR
                + BARRIER_LOGO
                + Constants.LINE_SEPARATOR
                + " :: Barrier :: (v" + VersionUtils.getVersion(getClass(), "1.0.0") + ")"
                + Constants.LINE_SEPARATOR;
    }

}
